package cn.xxstudy.visitshop.base.adapter

import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView

/**
 * @author ：DELL on 2021/3/24 .
 * @packages ：cn.xxstudy.visitshop.base.adapter .
 * TODO:Adapter基类
 */
abstract class BaseAdapter<T, VH : RecyclerView.ViewHolder> : RecyclerView.Adapter<VH>() {
    private var listener: OnItemClickListener<T>? = null
    var datas = ArrayList<T>()
        set(value) {
            field = value
            notifyDataSetChanged()
        }

    override fun getItemCount() = datas.size

    fun setOnItemClickListener(listener: OnItemClickListener<T>) {
        this.listener = listener
    }

    override fun onBindViewHolder(holder: VH, position: Int) {
        holder.itemView.setOnClickListener {
            listener?.let { it.onClickItem(position, datas[position]) }
        }
    }

}